package patterndesign.builder;

import java.util.ArrayList;
import java.util.List;

public abstract class CarModel {
    /**
     * 这个参数是各个方法的执行顺序
     */
    private List<String> sequence = new ArrayList<>();

    /**
     * 初始化 给sequence赋值
     *
     * @param sequence
     */
    public void setSequence(List<String> sequence) {
        this.sequence = sequence;
    }

    /**
     * 模型是启动开始跑了
     */
    protected abstract void start();

    /**
     * 停止
     */
    protected abstract void stop();

    /**
     * 喇叭会发出声音 是哔哔叫 还是滴滴叫
     */
    protected abstract void alarm();

    /**
     * 引擎发出隆隆声
     */
    protected abstract void engineBoom();

    final public void run() throws IllegalAccessException {
        for (String s : sequence) {
            // 全部转换为小写
            String actionName = s.toLowerCase();
            switch (actionName) {
                case "start":
                    this.start();
                    break;
                case "stop":
                    this.stop();
                    break;
                case "alarm":
                    this.alarm();
                    break;
                case "engine boom":
                    this.engineBoom();
                    break;
                default:
                    throw new IllegalAccessException("参数输入错误!");
            }
        }
    }

}
